def isPrime(f):
    if f == 1: return False
    test = True
    k = f - 1
    while k > 1:
        if not f % k:
            test = False
            break
        k -= 1
    return test

n = input()
c = []
for i in range(len(n)):
    for k in range(i + 1,len(n) + 1):
        f = int(n[i:k])
        if isPrime(f):
            c += [f]
print(max(c) if c else 0)